import { config ,baseApiUrl} from '../../config/cfg';
import {myCardList} from '../../model/hmbcard/hmbcard';
import { getRequest, postRequest} from '../../utils/request';
const { delay } = require('../../utils/delay');
const app = getApp();


export const getCardByNo=(cardNo)=> {
  // if (config.useMock) {
  //   return mockGetCardByNo(cardNo);
  // }else{
    return realGetCardByNo(cardNo);
  // }
 }

 function mockGetCardByNo(cardNo){
  return delay().then(()=>{
    let cs = myCardList.filter(item=>item.cardNo===cardNo);
    if(cs && cs.length>0){
      return cs[0];
    }else{
      return null;
    }
    
  });
 }

 function realGetCardByNo(cardNo){
  // var params = {url:baseApiUrl+'/真实子级地址?cardNo='+cardNo};
  let no = cardNo.slice(0, 19);
  let mask = cardNo.slice(19, 23);
  var params = {url:app.get_request_url("CardDetail", "coupons"),data:{cardNo:no, mask:mask}};
  return postRequest(params);
}
 

export const getMyCards=(mobile)=> {
  // if (config.useMock) {
  //   return mockGetMyCards(mobile);
  // }else{
    return realGetMyCards(mobile);
  // }
 }

 function mockGetMyCards(mobile){
  return delay().then(()=>{
    return myCardList;
  });
 }

 function realGetMyCards(mobile){
  // var params = {url:baseApiUrl+'/真实子级地址?mobile='+mobile};
  var params = {url:app.get_request_url("index", "coupons"),data:{mobile:mobile}};
  return postRequest(params);
}

